package ru.papergames.battleserver.model;


import ru.papergames.battleserver.network.WebServerClient;
import ru.papergames.battleserver.network.serverpackets.webserver.WebServerServerPacket;

/**
 * @author: atroshanin
 * Date: 19.09.2010
 * Time: 17:27:50
 */
public class WebServerClientHolder {
    private static final WebServerClientHolder instance = new WebServerClientHolder();

    private WebServerClient webServerClientBeforeAuth;
    private WebServerClient webServerClient;

    private WebServerClientHolder() {
    }

    public static WebServerClientHolder getInstance() {
        return instance;
    }

    public void setWebServerClient(WebServerClient webServerClient) {
        this.webServerClient = webServerClient;
    }

    public void sendPacketToWebServer(WebServerServerPacket packet) {
        WebServerClient client = webServerClient;
        if (client != null) {
            client.sendPacket(packet);
        }
    }

    public void setWebServerClientBeforeAuth(WebServerClient webServerClientBeforeAuth) {
        this.webServerClientBeforeAuth = webServerClientBeforeAuth;
    }

    public void sendForceReconnect(WebServerServerPacket packet) {
        WebServerClient client = webServerClientBeforeAuth;
        if (client != null) {
            client.sendPacket(packet);
        }
    }

    public boolean isWebServerClientReady() {
        return webServerClient != null;
    }
}
